import * as types from '../constants/helperTypes'
import { Post } from '../../utils'

const state = {
  city: []
}

const mutations = {
  [types.FETCH_GLOBAL_CONFIG] (state, payload) {
    state.city = payload.data.citys
  }
}

const actions = {
  /**
   * 获取城市列表
   */
  fetchCityList ({commit}) {
    Post('/api/configData', null).then(
      response => commit({
        type: types.FETCH_GLOBAL_CONFIG,
        data: response
      }),
      error => commit({
        type: types.FETCH_GLOBAL_CONFIG_FAILED,
        error
      })
    )
  }
}

export default {
  state,
  mutations,
  actions
}
